package Day17;

import java.lang.invoke.LambdaConversionException;
import java.util.Scanner;

public class TwoArrays {
    public static void main(String[] args) {
/*

        int[][] arr = new int[3][]; //创建二维数组，但是只是确定一维数组的个数
        for(int i = 0; i < arr.length; i++){
            arr[i] = new int[i + 1];
            for(int j = 0; j < arr[i].length; j++){
                arr[i][j] = i + 1;
            }
        }
        //给每一个一维数组开空间，new

            //遍历一维数组，给每一个一维数组赋值

        //遍历二维数组打印

        for(int i = 0; i < arr.length; i++){
            for(int j = 0 ; j < arr[i].length; j++){
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
*/
       /* int[][] arr = new int[3][];
        for(int i = 0;i < arr.length;i++){
            arr[i] = new int[i + 1];
            for(int j = 0 ; j < arr[i].length; j++){
                arr[i][j] = i + 1;
            }
        }

        for(int i = 0; i < arr.length;i++){
            for(int j = 0; j < arr[i].length; j++){
                System.out.print(arr[i][j] +" ");
            }
            System.out.println();
        }*/


        /*int[][] arr = {{1,2,3},{3,4,5},{6,7,8}};
        int sum = 0;
        for(int i = 0; i < arr.length; i++){
            for(int j = 0 ; j< arr[i].length;j++){
                sum += arr[i][j];
            }
        }

        System.out.println(sum);
*/

        //杨辉三角
       /* int[][] arr = new int[10][];
        for(int i =0;i < arr.length;i++){
            arr[i] = new int[i + 1];
            for(int j = 0; j < arr[i].length; j++){
                if(j == 0 || j == arr[i].length - 1){
                    arr[i][j] = 1;
                }else{
                    arr[i][j] = arr[i -1][j] + arr[i-1][j -1];
                }
            }
        }

        for(int i = 0; i < arr.length; i++){
            for(int j = 0; j < arr[i].length; j++){
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
*/
        /*int[][] arr = new int[10][];
        for(int i = 0; i < arr.length; i++){
            arr[i] = new int[i + 1];
            for(int j = 0; j < arr[i].length ; j++){
                if(j == 0 || j == arr[i].length - 1){
                    arr[i][j] = 1;
                }else{
                    arr[i][j] = arr[i-1][j] + arr[i-1][j-1];
                }
            }
        }
        for(int i = 0; i < arr.length; i++){
         for(int j = 0; j < arr[i].length; j++){
             System.out.print(arr[i][j] + " ");
         }

            System.out.println();
        }
*/


      /*  int[][] arr = new int[13][];
        for(int i = 0; i < arr.length; i++){
            arr[i] = new int[i + 1];
            for(int j = 0; j < arr[i].length; j++){
                if(j ==0 || j == arr[i].length-1){
                    arr[i][j] = 1;
                }else{
                    arr[i][j] = arr[i -1][j] + arr[i -1][j-1];
                }
            }
        }
        for(int i = 0; i < arr.length; i++){
            for(int j = 0; j < arr[i].length; j++){
                System.out.print(arr[i][j] + "\t");
            }
            System.out.println();
        }
*/
        int[] arr = {10,12,45,90};
        int[] arr2 = new int[arr.length + 1];
        for(int i = 0; i < arr.length; i++){
            arr2[i] = arr[i];
        }
        System.out.println("请输入一个元素");
        Scanner sc = new Scanner(System.in);
        int addNum = sc.nextInt();
        arr2[arr2.length - 1] = addNum;
        arr = arr2;
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }

        System.out.println("\n====排序之后是这样子的=====");
        for(int i = 0; i < arr.length -1 ; i++){
            int temp = 0;
            for(int j = 0; j < arr.length - 1 - i; j++){
                if(arr[j] > arr[j + 1]) {
                    temp = arr[j + 1];
                    arr[j+ 1] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }

    }
}
